import 'package:hive_flutter/hive_flutter.dart';
import 'dart:convert';

class StorageService {
  static late final Box _hiveBox;

  static Future<void> init() async {
    await Hive.initFlutter();
    _hiveBox = await Hive.openBox('storage');
  }

  // 使用泛型和实例方法，更易于测试和注入
  Future<void> setString(String key, String val) => _hiveBox.put(key, val);
  String getString(String key, {String defaultValue = ''}) => _hiveBox.get(key, defaultValue: defaultValue) as String;

  Future<void> setInt(String key, int val) => _hiveBox.put(key, val);
  int getInt(String key, {int defaultValue = 0}) => _hiveBox.get(key, defaultValue: defaultValue) as int;

// ... 其他方法保持类似模式
}